<script setup>
import {infoStore} from "@/store";
import {reactive, watch} from "vue";

const store = infoStore()
const {updatePlayListInfo, updatePlayListIndex} = store
const props = defineProps(['lists'])
const state = reactive({
    lists: []
})
state.lists = props.lists
watch(props, () => {
    state.lists = props.lists
})

function playMusic(index) {
    console.log(state.lists)
    // 更新播放列表
    updatePlayListInfo(state.lists)
    // 更新播放曲目
    updatePlayListIndex(index)
}
</script>

<template>
    <div class="list">
        <div v-for="(item,i) in state.lists" :key="item" class="item">
            <div class="itemLeft" @click="playMusic(i)">
                <span class="leftSpan">{{ i + 1 }}</span>
                <div>
                    <p>{{ item.name }}</p>
                    <span v-for="(author,index) in item.ar">{{ author.name }}
                            <span v-if="index+1>0 && index+1<Object.keys(item.ar).length">/ </span>
                        </span>
                </div>
            </div>
            <div class="itemRight">
                <svg v-if="item.mv!==0" aria-hidden="true" class="icon movieIcon">
                    <use xlink:href="#icon-shipin"></use>
                </svg>
                <svg aria-hidden="true" class="icon listIcon">
                    <use xlink:href="#icon-31liebiao"></use>
                </svg>
            </div>
        </div>
    </div>
</template>

<style lang="less" scoped>
.list {
    width: 100%;

    .item {
        width: 100%;
        height: 1.4rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 0.2rem;

        .itemLeft {
            width: 60%;
            height: 100%;
            display: flex;
            align-items: center;

            .leftSpan {
                display: inline-block;
                width: 0.2rem;
                text-align: center;
            }

            div {
                p {
                    width: 4.54rem;
                    height: 0.4rem;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    font-weight: 700;
                }

                span {
                    font-weight: 400;
                    font-size: 0.24rem;
                    color: #999;
                }

                margin-left: 0.3rem;
            }
        }

        .itemRight {
            width: 20%;
            height: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: relative;

            .icon {
                fill: #999;
            }

            .movieIcon {
                position: absolute;
                left: 0;
            }

            .listIcon {
                position: absolute;
                right: 0;
            }
        }
    }
}
</style>